package practise.alogrithm.hundredInterviewQuestions.secondTime;

import practise.alogrithm.hundredInterviewQuestions.Utils.TreeBuilder;
import practise.alogrithm.hundredInterviewQuestions.Utils.TreeNode;

/**
 * Created by Richard on 7/26/2014.
 */
public class MirrorTree {
    public void convert(TreeNode node){
        if(node.getLeft()==null && node.getRight()==null){
            return;
        }
        TreeNode temp = node.getLeft();
        node.setLeft(node.getRight());
        node.setRight(temp);

        convert(node.getRight());
        convert(node.getLeft());
    }


    public static void main(String[] args){
        TreeNode treeNode = TreeBuilder.createTreeByArrayInWidth(new int[]{1,2,3,4,5,6,7});
        MirrorTree mirrorTree = new MirrorTree();
        mirrorTree.convert(treeNode);

        TreeBuilder.printTreeWithLevel(treeNode);
    }
}
